const serviceConfigMap: App.Service.ServiceConfigMap = {
  dev: {
    baseURL: 'http://localhost:8088',
    otherBaseURL: {
      demo: 'http://localhost:9528'
    }
  },
  test: {
    baseURL: 'http://localhost:8088',
    otherBaseURL: {
      demo: 'http://localhost:9529'
    }
  },
  prod: {
    baseURL: 'http://localhost:8088',
    otherBaseURL: {
      demo: 'http://localhost:9530'
    }
  }
};

/**
 * Create service config by current env
 *
 * @param env The current env
 */
export function createServiceConfig(env: Env.ImportMeta) {

  const {VITE_SERVICE_ENV = 'dev'} = env;

  return serviceConfigMap[VITE_SERVICE_ENV];
}

/**
 * Get proxy pattern of service url
 *
 * @param key If not set, will use the default key
 */
export function createProxyPattern(key?: App.Service.OtherBaseURLKey) {
  if (!key) {
    return '/api';
  }
  return `/api/${key}`;
}

/**
 * 获取当前环境模式下的请求服务的配置
 * @param env 环境
 */
export function getServiceEnvConfig(env: Env.ImportMeta): App.Service.ServiceConfig {
  const {VITE_SERVICE_ENV = 'dev'} = env;

  const config = serviceConfigMap[VITE_SERVICE_ENV];
  return {
    ...config,
    proxyPattern: createProxyPattern(),
  };
}

